<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/socket.io/socket.io.js"/>
    <script type="text/javascript">
        const socket = io.connect('http://localhost:3000');
        socket.on('message', function (message) {
            console.log('data from server:' + message);
        });
        socket.on('disconnect', () => {
            console.log('disconnect');
        });

        // 监听服务器自定义的事件
        socket.on('serverEvent', (data) => {
            console.log('serverEvent:' + data);

            // 自定义事件，事件名称：clientEvent，
            // 第二个参数是事件的内容，可以是字符串，也可以是对象
            socket.emit('clientEvent', {address :'taiYuna', age: 20});

        });

        // 自定义广播事件
        socket.emit('broadcastEventClient', 'take care');

        socket.on('broadcastEventServer', (message) => {
            console.log(message);
        });

    </script>
</head>
<body>

</body>
</html>